package com.service.impl;

import com.dao.DeSignUpDAO;
import com.dao.EquipDAO;
import com.dao.SignUpDAO;
import com.model._do.DeSignDO;
import com.model._do.SignUpDO;
import com.service.DeSignUpService;
import com.service.SignUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service("deSignUpService")
public class DeSignUpServiceImpl implements DeSignUpService {

    @Autowired
    private DeSignUpDAO deSignUpDAO;

    @Autowired
    private EquipDAO equipDAO;

    @Autowired
    private SignUpDAO signUpDAO;

    @Override
    public void addNewDeSign(DeSignDO design) {
        deSignUpDAO.addNewDeSign(design);
    }

    @Override
    public int getDeSignNumByToId(String id) {
        return deSignUpDAO.getDeSignNumByToId(id);
    }

    @Override
    public void agreeDeSignById(String id) {
        deSignUpDAO.agreeDeSignById(id);
    }

    @Override
    public void deleteDeSign(DeSignDO deSign) {
        deSignUpDAO.deleteDeSign(deSign);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void confirmDeSign(DeSignDO deSign) {
        deSignUpDAO.confirmDeSign(deSign);
        SignUpDO sign = signUpDAO.getSignedByUserEquip(deSign.getFrom(), deSign.getTo());
        if(deSign.getFrom().equals(sign.getEquipId())){
            sign.setPatientConfirm("disagree");
        } else if (deSign.getFrom().equals(sign.getUserId())){
            sign.setDoctorConfirm("disagree");
        }
        signUpDAO.deleteSignUp(sign);
    }

    @Override
    public DeSignDO getDeSignById(String id) {
        return deSignUpDAO.getDeSignById(id);
    }

    @Override
    public DeSignDO getDeSignByFromToId(String fromId, String toId) {
        return deSignUpDAO.getDeSignByFromToId(fromId, toId);
    }

    @Override
    public List<DeSignDO> getDeSignListByToId(String id) {
        return deSignUpDAO.getDeSignListByToId(id);
    }
}
